package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.SystemOperationLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 操作日志 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2025-08-27
 */
@Mapper
public interface SystemOperationLogMapper extends BaseMapper<SystemOperationLog> {
    @Select({
            "<script>",
            "SELECT",
                "sl.*,",
                "d.name AS operation_type_name,",
                "CASE WHEN sl.created_id = 1568138350324350975 THEN '管理员' ELSE s.name END as created_name",
            "FROM",
                "system_operation_log sl",
                "INNER JOIN staff s on s.id = sl.created_id",
                "LEFT JOIN dict d on d.num = sl.operation_type AND d.type = 43",
            "WHERE",
                "1=1",
                "<if test='yearPart!=null and yearPart != &apos;&apos;'>",
                    "AND sl.year_part = ${yearPart}",
                "</if>",
                "<if test='quarterNum!=null and quarterNum != &apos;&apos;'>",
                    "AND sl.quarter_num = ${quarterNum}",
                "</if>",
                "<if test='operationType!=null and operationType != &apos;&apos;'>",
                    "AND sl.operation_type = ${operationType}",
                "</if>",
                "<if test='startDate!=null and startDate != &apos;&apos; and endDate!=null and endDate != &apos;&apos;'>",
                    "AND DATE(sl.created_at) between '${startDate}' and '${endDate}'",
                "</if>",
                "<if test='teacherName!=null and teacherName != &apos;&apos;'>",
                    "AND s.name like '%${teacherName}%'",
                "</if>",
            "ORDER BY sl.created_at DESC",
            "</script>",
    })
    IPage<SystemOperationLog> pageList(
            IPage<?> page,
            @Param("yearPart") Integer yearPart,
            @Param("quarterNum") Integer quarterNum,
            @Param("startDate") String startDate,
            @Param("endDate") String endDate,
            @Param("teacherName") String teacherName,
            @Param("operationType") Integer operationType);
}
